package com.mm.gbicc.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mm.gbicc.bean.Menu;
import com.mm.gbicc.dao.FileDao;

/**
 * Servlet implementation class GetMenu
 */
public class GetMenu extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetMenu() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter outPrintWriter = response.getWriter();
		String pid = request.getParameter("id");
		//System.out.println("--->"+pid);
		if(pid==null||"0".equals(pid))
			pid = "1000182855";
		FileDao dao = new FileDao();
		
		StringBuilder sb = new StringBuilder();
		List<Menu> menus = dao.getmenuS(pid,"1");
		
		dao.getForJson(dao, sb, menus);
		
		//request.setAttribute("menu", sb.toString());
		//System.out.println(sb.toString());
		
		outPrintWriter.print(sb.toString());
		outPrintWriter.flush();
		outPrintWriter.close();
	}
	public static void main(String[] args) {
		String url = "http://168.1.6.181/ibmcognos/cgi-bin/cognos.cgi?" +
				"b_action=cognosViewer&ui.action=run&ui.object=%2fcontent%" +
				"2ffolder%5b%40name%3d%27%e5%8d%8e%e6%b6%a6%e4%b8%87%e5%ae%b6%e4%b8%9a%e5%8a%a1%e6%8a%a5%e8%a1%a8%27%5d" +
				"%2ffolder%5b%40name%3d%2702%20%e9%94%80%e5%94%ae%e5%91%a8%e6%8a%a5____________________________(%e6%9" +
				"5%b0%e6%8d%ae%e6%ad%a3%e5%b8%b8%e7%94%9f%e6%88%90%e6%97%b6%e9%97%b4%e4%ba%8e%e6%af%8f%e5%a4%a914%" +
				"ef%bc%9a30)%27%5d%2freport%5b%40name%3d%271-1-1%20%e5%8d%8e%e6%b6%a6%e4%b8%87%e5%ae%b6%e9%94%80%" +
				"e5%94%ae%e5%91%a8%e6%8a%a5%27%5d&ui.name=1-1-1%20%e5%8d%8e%e6%b6%a6%e4%b8%87%e5%ae%b6%e9%94%80%e" +
				"5%94%ae%e5%91%a8%e6%8a%a5&run.outputFormat=&run.prompt=true&ui.backURL=%2fcognos8%2fcgi-bin%2fmod" +
				"2_cognos.dll%3fb_action%3dxts.run%26m%3dportal%2fcc.xts%26m_folder%3di0ADEC02E93484FB9B079B7E66CD" +
				"460DE&CAMUsername=admin&CAMPassword=6y7u"	;
		//url = "http://168.1.18.48:8080/fileManage/pdfImport.jsp?null&CAMUsername=admin&CAMPassword=6y7u";
		//url = "http://localhost/reportPortal/report/http://oif.cre.com.hk:80/fed/idp/initiatesso?providerid=http://oif.crc.com.cn:80/fed/sp&returnurl=http://portaluat.crc.com.cn/oif/CRCPortal/index.jsp?oif_redirect_url=http://10.0.96.99:9802/analytics";
		//url = "http://oif.cre.com.hk:80/fed/idp/initiatesso?providerid=http://oif.crc.com.cn:80/fed/sp&returnurl=http://portaluat.crc.com.cn/oif/CRCPortal/index.jsp?oif_redirect_url=http://10.0.96.99:9802/analytics";
		if(url.indexOf("?null&CAMUsername")>0){
			System.out.println(url.substring(0,url.indexOf("?null&CAMUsername")));
		}else{
			System.out.println(url.substring(0,url.indexOf("&CAMUsername")));
				
		}
	}
}
